package DAO;

import java.sql.Connection;
import java.sql.Date;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

import java.sql.SQLException;

import oracle.sql.DATE;

public class ConsultaAppporClinic {
  public Object[] ConsultaAppporClinic1(Date inicio, Date fin,
                                          int clinicNumber) {
    Conexion conexion = new Conexion();
    Connection conex;
    Object[]datos = new Object[100][100];
    try {
      conex = conexion.getConnection();
      PreparedStatement ps = null;
      ResultSet rs = null;

      ps =
          conex.prepareStatement("select * from appointment where dateA between  ? and ? and clinicnumber = ?");
      String fecha = String.valueOf(inicio);
      String fecha1 = String.valueOf(fin);
      ps.setString(1, fecha);
      ps.setString(2, fecha1);
      ps.setInt(3, clinicNumber);

      rs = ps.executeQuery();
      int i = 0;
      int j = 0;
      datos[i] = " APPOINMENT NUMBER";
      j++;
      datos[i] = "DATE";
      j++;
      datos[i] = "TYPEA";
      j++;
      datos[i]= "CLINIC NUMBER";
      j++;
      datos[i]= "OWNER NAME";
      j++;
      datos[i]= "HOUR START";
      j++;
      datos[i]= "MIN START";
      j++;
      datos[i]= "DURACION";
      j++;
      datos[i]= "PET ID";
      i++;

      while (rs.next()) {
        
        datos[i] = rs.getInt(1);
        System.out.print(datos[i] + " ");
        j++;
        datos[i] = rs.getString(2);
        System.out.print(datos[i] + " ");
        j++;
        datos[i] = rs.getString(3);
        System.out.print(datos[i] + " ");
        j++;
        datos[i]= rs.getInt(4);
        System.out.print(datos[i] + " ");
        j++;

        datos[i] = rs.getInt(5);
        System.out.print(datos[i]+ " ");
        j++;
        datos[i]= rs.getInt(6);
        System.out.print(datos[i] + " ");
        j++;
        datos[i] = rs.getInt(7);
        System.out.print(datos[i] + " ");
        j++;
        datos[i] = rs.getInt(8);
        System.out.print(datos[i] + " ");
        j++;
        datos[i] = rs.getInt(9);
        System.out.print(datos[i] + " ");
        i++;
        j = 0;
      }
    } catch (SQLException e) {
    }
    return datos;
  }


  public Object[] consultarFechas() {
    Conexion conexion = new Conexion();
    Connection conex;
    Object[] datos = new Object[100];
    try {
      conex = conexion.getConnection();
      PreparedStatement ps = null;
      ResultSet rs = null;

      ps =
          conex.prepareStatement("select distinct dateA from appointment order by dateA");

      rs = ps.executeQuery();
      int i = 0;
      while (rs.next()) {
        datos[i] = rs.getString(1);
        i++;
      }


    } catch (Exception e) {
    }
    return datos;
  }

  public Object[] consultarClinicas() {

    Conexion conexion = new Conexion();
    Connection conex;
    Object[] datos = new Object[100];
    try {

      conex = conexion.getConnection();
      PreparedStatement ps = null;
      ResultSet rs = null;

      ps =
          conex.prepareStatement("select distinct clinicnumber from clinic order by clinicnumber");

      rs = ps.executeQuery();
      int i = 0;

      while (rs.next()) {
        datos[i] = rs.getInt(1);
        System.out.println(datos[i]);
        i++;
      }


    } catch (Exception e) {
    }
    return datos;
  }
}
